#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string reverseWords(string s) {
        string temp = s;
        string::iterator it1 = temp.begin();
        string::iterator it2 = temp.begin();
        while (it1 != temp.end())
        {
            if (*it2 == ' ')
            {
                reverse(it1, it2);
                it1 = ++it2;
            }
            if (it2 == temp.end())
            {
                reverse(it1, it2);
                return temp;
            }
            it2++;
        }
        return temp;
    }
};
